/******************************************************************************
 cnome: A C++ source "genes" discover. :-)

 See more details at:

   http://www.codeplex.com/cnome

 The original author site is at: http://www.alemosbarbosa.com/

 Copyright (c) 2008-2010 Alexandre Lemos Barbosa.
 Distributed under the MIT License. (See accompanying file LICENSE-MIT.txt 
 or at http://www.codeplex.com/cnome/license)
 ******************************************************************************/

#ifndef UTIL_H
#define UTIL_H

#include <string>

#include "typedefs.h"
#include "parameter.h"

namespace cnome { namespace util {
    class sglUtil
    {
    public:
        enum parser_state
        {
            unknown,
            inside_function_body,
            outside_function_body

        };

        static sglUtil* instance()
        {
            if (!m_instance)
                m_instance = new sglUtil;

            return m_instance;
        }
        parser_state get_state() { return m_state; }
        void set_state(parser_state s) { m_state = s; }

    private:
        static sglUtil* m_instance;
        parser_state m_state;
        sglUtil():m_state(unknown) {}
    };

    enum sblAttribute
    {
        None        = 0x00,
        Array       = 0x01,
        PtrToFct    = 0x02,
        Method      = 0x04,
        MethodConst = 0x08,
        TypeDefDcl  = 0x10,
        Builtin     = 0x20,
        Operator    = 0x40,
        OperatorCvs = 0x80
    };

    sblAttribute operator|(sblAttribute a, sblAttribute b);

    sblAttribute mmbSblToStr(iterator& first, const iterator& last, std::string& val, std::string& strAux, adornersT& adrns);

    const symbolPtr& GetMthToken();
    void suffixMethodName(std::string&);
    void suffixMethodName(std::string& val, scopeT& tmplPrms, adornersT* adorners);
    const char* getSuffixForSymbol(const symbol& smb);
    std::string& sblToStr(const iterator& first, const iterator& last, std::string& val);
    std::string& sblToStr(iterator& first, const iterator& last, std::string& val, adornersT& adrns, std::size_t& suffixSize);
    void appendAdorners(std::string& val, const adornersT& adrns, std::size_t& suffixSize);
    void appendAdorners(std::string& val, const adornersT& adrs);
    symbolPtr declPtrToFct(const std::string& strTypeDecl, iterator& first);
    sblAttribute mtdSblToStr(iterator& first, const iterator& last, std::string& val, std::string& mthName, adornersT& adrns);
    itSymbolItem verifyMethodName(iterator& first, const std::string& curScope, bool& isDataMember, bool& reDeclaration);
    bool isCtorDecl(const std::string& curScope);
    bool verifyCtorDecl(bool ctorDecl, symbolPtr& smb, iterator& first);
    void adjustPrmVars(symbolPtr& smb);
    void declareParameters(itSymbolItem& it);
    bool verifyReturnType(itSymbolItem& it, symbolPtr& smb, iterator first);
    bool compareParameters(itSymbolItem& it, symbolPtr& smb, iterator first);
    int get_level(constItPrms& it);
    int get_level(itPrms& it);
    int get_level(constRevItPrms& rit);
    int get_level(itRevPrms& rit);
    itSymbolItem findTypeDecl(const std::string& str, iterator& first);
    std::string calculateIdxPrms(int level, int pos);
    std::string calculateIdxTmplPrms(int level, int pos);
    constItPrms beginPrmVars(int level);
    itPrms beginPrmVars(bool, int level);
    itPrms beginPrmVars(bool);
    constItPrms beginTmplPrmVars(int level);
    constItPrms beginTmplPrmVars();
    itPrms beginTmplPrmVars(bool, int level);
    itPrms beginTmplPrmVars(bool);
    constItPrms& incItPrmVars(constItPrms& it, int level);
    constItPrms& incItPrmVars(constItPrms& it);
    constItPrms& incItTmplPrms(constItPrms& it, int level);
    constItPrms& incItTmplPrmVars(constItPrms& it, int level);
    constItPrms& incItTmplPrmVars(constItPrms& it);
    void handleTypeDefSymbol(itSymbolItem& it);
    bool isCtorDeclWithoutParent(const std::string& curScope);
    void handle_typdef_struct_X_X(itSymbolItem& it);
    void adjustTmplPrms(iterator first, iterator last);
    void adjustTmplPrms(symbolPtr& smb);
    lvlConstItPrms findInTmplPrms(const char* val_str);
}} // namespace cnome { namespace util {

#endif // UTIL_H

